**** This file replicates results from CCES modules ****

use "combined_cces_file.DTA", clear

svyset [pw=weight]

*Gender Recode*
recode gender 2=1 1=0, gen(female)
label define female 0 "Male" 1 "Female"
label values female female
label variable female "Female"

*Income Recode*
gen incomecat=1 if faminc<=4
replace incomecat=2 if faminc>4 & faminc<10
replace incomecat=3 if faminc<97 & faminc>=10
replace incomecat=0 if faminc==97

label define incomecat 1 "Less than $40k" 2 "$40k - $100k" 3 "Over $100k"
label values incomecat incomecat

*Ideology Recode*
gen ideo3=ideo5
recode ideo3 1/2=1 3=2 4/5=3 6=4
label define ideo3 1 "liberal" 2 "moderate" 3 "conservative"
label val ideo3 ideo3
label var ideo3 "Ideology 3 point"
recode ideo5 1=0 2=.25 3=.5 4=.75 5=1 6=.

*Party ID Recode*
recode pid3 4/5=3
recode pid7 1=0 2=.17 3=.34 4=.5 5=.67 6=.84 7=1 8=.5

*Age Recode*
gen age=2016-birthyr
gen agecat=1 if age<30
replace agecat=2 if age>29 & age<55
replace agecat=3 if age>54

label define agecat 1 "18-29" 2 "30-54" 3 "55+"
label values agecat agecat

*Race Recode*
recode race 4/9=0, gen(racecat)
replace race=3 if hispanic==1
label values racecat RACE

*Education Recode*
recode educ 1/2=1 3/4=2 5=3 6=4, gen(educcat)
label define educcat 1 "HS or less" 2 "Some college" 3 "College degree" 4 "Postgraduate"
label values educcat educcat

recode educcat 3/4=1 1/2=0, gen(college)
label variable college "College degree"
label define college 0 "No degree" 1 "College degree"
label values college college

recode educ 1/2=1 3/4=2 5=3 6=4, gen(educ2)
label define educ2 1 "HS or less" 2 "Some college" 3 "College graduate" 4 "Post-graduate"
label values educ2 educ2

* Variable for South/Non-South
gen south=1 if inputstate==1 | inputstate==5 | inputstate==12 | inputstate==13 | inputstate==21 | inputstate==22 | inputstate==28 | inputstate==37 | inputstate==45 | inputstate==47 | inputstate==48 | inputstate==51 | inputstate==54 
recode south .=0


* DVs Recode
recode CC16_410a 2=0 3/10=., gen(prezvote)
recode CC16_410a 2=0 3/5=3 6/7=. 8=3, gen(prezvote2)

gen prezvoteintent=1 if (CC16_364c==1 | CC16_364b==1) & CC16_364==1
replace prezvoteintent=0 if (CC16_364c==2 | CC16_364b==2) & CC16_364==1

recode CC16_326 2=1 1=0 3/9=., gen(prezvote2012)

gen votes=0 if prezvote==0 & prezvote2012==0
replace votes=1 if prezvote==1 & prezvote2012==1
replace votes=2 if prezvote==1 & prezvote2012==0
replace votes=3 if prezvote==0 & prezvote2012==1


* Racial Resentment scale
recode UMA301_1-UMA301_4 (6=.)
irt grm UMA301_1-UMA301_4
predict resentment, latent
gen resentment_scaled=(resentment+1.840217)/3.505471
label var resentment_scaled "Racial resentment scale"

* Build sexism scale
irt grm UMA306a -UMA306d
predict sexism, latent
gen sexism_scaled=(sexism+1.521393)/3.627762
label var sexism_scaled "Hostile sexism scale"

  
* Build denial of racism scale
recode CC16_422f 1=6 2=5 3=4 4=3 5=2 6=1, gen(CC16_422f_reversed)
irt grm CC16_422c CC16_422d CC16_422f_reversed
predict racism, latent
gen racism_scaled=(racism+1.298584)/3.700837
label var racism_scaled "Denial of Racism scale"

* Generate dummy variable for white
recode race 2/9=0, gen(white)

* Economic satisfaction items
recode CC16_303 5=1 4=.75 3=.5 2=.25 1=0, gen(hhincome)
label var hhincome "Change in HH Income"

**** Histograms (Figures 2 and 3)

twoway histogram CC16_303, discrete percent title("CCES" "HH Income Change") barw(.5) bc(gs4) xlabel(,angle(45) val) xtitle(" ") aspect(1) plotr(lc(none)) saving(economycces, replace) scheme(s1color)
twoway histogram sexism, discrete percent title("CCES" "Hostile Sexism") xtitle(" ") w(.05) xlabel(-2 -1 0 1 2)  bc(gs4)  aspect(1) plotr(lc(none)) saving(sexismcces, replace)
twoway histogram racism, discrete percent title("CCES" "Racism Denial") bc(gs4)  w(.05) xlabel(-2 -1 0 1 2)  xtitle(" ") aspect(1) plotr(lc(none)) saving(racismcces, replace)

twoway histogram CC16_303 if racecat==1, discrete percent title("CCES" "HH Income Change") barw(.5) bc(gs4) xlabel(,angle(45) val) xtitle(" ") aspect(1) plotr(lc(none)) saving(economycces_whites, replace) scheme(s1color)
twoway histogram sexism if racecat==1, discrete percent title("CCES" "Hostile Sexism") xtitle(" ") w(.05) xlabel(-2 -1 0 1 2)  bc(gs4)  aspect(1) plotr(lc(none)) saving(sexismcces2, replace)
twoway histogram racism if racecat==1, discrete percent title("CCES" "Racism Denial") bc(gs4)  w(.05) xlabel(-2 -1 0 1 2)  xtitle(" ") aspect(1) plotr(lc(none)) saving(racismcces2, replace)


**** Models in Table 2 (columns 3 and 4)

svy: probit prezvote sexism_scaled racism_scaled hhincome ideo5 pid7 female i.agecat college  i.incomecat i.racecat south if race==1

svy: probit prezvote sexism_scaled racism_scaled hhincome ideo5 pid7 female i.agecat college  i.incomecat i.racecat south

* Figure 4
margins, at(hhincome=(0(.25)1))
marginsplot,  title("HH Income Change") xtitle(" ") xlabel(0 `" "Increased" "a lot" "' 1 `" "Decreased" "a lot  " "') ytitle("Prob. of voting for Trump") saving(economic, replace) plotopt(lw(thick) msize(0) lc(black)) recastci(rarea) ciopt(col(gs10)) aspect(1)
margins, at(sexism_scale=(0(.2)1))
marginsplot,  title("Hostile Sexism") xtitle(" ") xlabel(0 `" "Least" "sexist" "' 1 `" "Most" "sexist" "') ytitle("Prob. of voting for Trump") saving(sex, replace)  plotopt(lw(thick) msize(0) lc(black)) recastci(rarea) ciopt(col(gs10)) aspect(1)
margins, at(racism_scale=(0(.2)1))
marginsplot,  title("Acknowledgement of Racism") xtitle(" ") xlabel(0 `" "Most acknowledging" "of racism" "' 1 `" "Most denying      " "of racism" "') ytitle("Prob. of voting for Trump")  saving(race, replace)  plotopt(lw(thick) msize(0) lc(black)) recastci(rarea) ciopt(col(gs10)) aspect(1)
graph combine economic.gph sex.gph race.gph, title("CCES Module") ycom col(3) iscale(.9) ysize(2) xsize(4.5) saving(fig4b, replace)


**** Models in Table 3/Figure 5

svy: biprobit (prezvote2012 = sexism_scaled racism_scaled hhincome ideo5 pid7 female i.agecat college  i.incomecat i.racecat south) (prezvote = sexism_scaled racism_scaled hhincome ideo5 pid7 female i.agecat college  i.incomecat i.racecat south) if age>=21
test [prezvote2012]sexism_scaled=[prezvote]sexism_scaled
test [prezvote2012]racism_scaled=[prezvote]racism_scaled
test [prezvote2012]hhincome=[prezvote]hhincome

margins, at(hhincome=(0(.25)1)) predict(p10) saving(romneyclinton, replace)
margins, at(hhincome=(0(.25)1)) predict(p01) saving(obamatrump, replace)

combomarginsplot romneyclinton obamatrump, title("HH Income Change") file1(lc(gs10) mc(gs10)) fileci1(lc(gs10)) file2(lc(black) mc(black)) fileci2(lc(black)) aspect(1) legend(order(3 "Romney -> Clinton" 4 "Obama -> Trump") col(1)) ytitle("Probability")  xlabel(0 "Increased" 1 "Decreased     ")  plotr(lc(none)) saving(hhincome_compare, replace)

margins, at(sexism_scale=(0(.2)1)) predict(p10) saving(romneyclinton, replace)
margins, at(sexism_scale=(0(.2)1)) predict(p01) saving(obamatrump, replace)

combomarginsplot romneyclinton obamatrump, title("Hostile Sexism") file1(lc(gs10) mc(gs10)) fileci1(lc(gs10)) file2(lc(black) mc(black)) fileci2(lc(black)) aspect(1) legend(order(3 "Romney -> Clinton" 4 "Obama -> Trump") col(1)) ytitle("Probability")  xlabel(0 "Least sexist" 1 "Most sexist     ")  plotr(lc(none)) saving(sexism_compare, replace)

margins, at(racism_scale=(0(.2)1)) predict(p10) saving(romneyclinton, replace)
margins, at(racism_scale=(0(.2)1)) predict(p01) saving(obamatrump, replace)

combomarginsplot romneyclinton obamatrump, title("Racism Denial") file1(lc(gs10) mc(gs10)) fileci1(lc(gs10)) file2(lc(black) mc(black)) fileci2(lc(black)) aspect(1) legend(order(3 "Romney -> Clinton" 4 "Obama -> Trump") col(1)) ytitle("Probability") xlabel(0 "Least denying" 1 "Most denying     ")  plotr(lc(none)) saving(racism_compare, replace)

svy: biprobit (prezvote2012 = sexism_scaled racism_scaled hhincome ideo5 pid7 female i.agecat college  i.incomecat south) (prezvote = sexism_scaled racism_scaled hhincome ideo5 pid7 female i.agecat college  i.incomecat south) if age>=21 & race==1


**** Models in Table 4

svy: reg prezvote college  if race==1 
svy: reg prezvote college hhincome  if race==1 
svy: reg prezvote college sexism_scaled if race==1 
svy: reg prezvote college  racism_scaled  if race==1 
svy: reg prezvote college sexism_scaled racism_scaled  if race==1 




